#include <iostream>
#include <cstring>
using namespace std;
#define maxn 31
#define maxv 20001

int n,V;
int volume[maxv];
int dp[maxn][maxv];

int dfs(int i, int v){
	/*
	@param i: index of current good;
	@param v: current volume of bag;
	@return: increased max volume of bag;
	*/
	if(dp[i][v]>=0) return dp[i][v];
	if(i==n || v>=V) return 0;
	int ret1 = dfs(i+1, v);
	int ret2 = 0;
	if(v+volume[i] <= V)
		ret2 = dfs(i+1, v+volume[i]) + volume[i];

	return max(ret1, ret2);
}

int main(){
	memset(dp,-1,sizeof(dp));
	cin>>V>>n;
	for(int i=0; i<n; i++){
		cin>>volume[i];
	}

	cout << V-dfs(0,0) << endl;

	return 0;
}